package de.moc.server;

import java.util.Vector;

import de.moc.client.SurveyService;
import de.moc.shared.*;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class SurveyServiceImpl extends RemoteServiceServlet implements
		SurveyService {

	private DataAccess da = new DataAccess();

	@Override
	public String newSurvey(Survey survey) throws SurveyException {
		da.endActiveSurvey();
		return da.saveSurvey(survey, true);
	}

	@Override
	public Survey getResult(String id) throws SurveyException {
		return da.getSurvey(id);
	}

	@Override
	public boolean deleteSurvey(String id) throws SurveyException {
		return da.removeSurvey(id);
	}

	@Override
	public boolean endActiveSurvey() throws SurveyException {
		return da.endActiveSurvey();
	}

	@Override
	public Survey getActiveSurvey() throws SurveyException {
		return da.getActiveSurvey();
	}

	@Override
	public String addExampleSurvey() throws SurveyException {
		da.endActiveSurvey();
		return da.saveSurvey(new DefaultSurvey(), true);
	}

	@Override
	public Vector<Survey> getAllSurveys() throws SurveyException {
		return da.getAllSurveys();
	}

	@Override
	public Survey resetSurvey(String id) throws SurveyException {
		return da.resetSurvey(id);
	}
}
